import { createStore } from 'vuex'

export default createStore({
  state: {
    userInfo: {
      // name: 'admin',
      // uid: '',
      // phone: '18581505995' // 手机号码
      name: '',
      uid: '',
      phone: '' // 手机号码
    }
  },

  getters: {
    // 当前是否登录
    isRegister: (state) => (Boolean(state.userInfo.name))
  },

  mutations: {
    // 更新 userInfo
    SET_USER_INFO (state, user) {
      Object.assign(state.userInfo, user)
    },
    /**
     * 更新state, 不用写那么多的mutations  使用方法 例: this.$store.commit('updata', {"cityName":"北京"})
     */
    UPDATE (state, config) {
      Object.keys(config).map((item) => {
        state[item] = config[item]
      })
    }
  }
})
